package cn.bsuc.crm.service.impl;

import cn.bsuc.crm.dto.PlanDTO;
import cn.bsuc.crm.entity.CusDevPlan;
import cn.bsuc.crm.entity.SaleChance;
import cn.bsuc.crm.mapper.CusDevPlanMapper;
import cn.bsuc.crm.service.CusDevPlanService;
import cn.bsuc.crm.service.SaleChanceService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhuoyuan
 * @since 2022-10-03
 */
@Service
public class CusDevPlanServiceImp extends ServiceImpl<CusDevPlanMapper, CusDevPlan> implements CusDevPlanService {

    @Autowired
    private SaleChanceService saleChanceService;

    @Override
    @Transactional
    public int savePlan(PlanDTO planDTO) {
        SaleChance byId = saleChanceService.getById(planDTO.getPid());
        byId.setDevResult(2);
        boolean b = saleChanceService.updateById(byId);
        planDTO.setSaleChanceId(planDTO.getPid());
        if (planDTO.getId()==null){
            int insert = baseMapper.insert(planDTO);
            return 1;
        }
        int i = baseMapper.updateById(planDTO);
        return 1;
    }
}
